package com.acompany.testapp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class Test extends Activity implements View.OnClickListener {

	private TextView operand2;
	private TextView operand1;
	private Spinner operatorList;
	private TextView answer;

	private static final String[] operatorItems = { "+", "-", "*", "/" };

	/** Called when the activity is first created. */
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);

		setContentView(R.layout.calculator);
		operand1 = (TextView) findViewById(R.id.operand1);

		operatorList = (Spinner) findViewById(R.id.operatorList);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_spinner_item, operatorItems);
		adapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		operatorList.setAdapter(adapter);

		operand2 = (TextView) findViewById(R.id.operand2);
		answer = (TextView) findViewById(R.id.answer);
		Button b = (Button) findViewById(R.id.calculate);
		b.setOnClickListener(this);

	}

	public void onClick(View view) {
		Integer v1 = Integer.valueOf(operand1.getText().toString());
		Integer v2 = Integer.valueOf(operand2.getText().toString());
		String op = (String) operatorList.getSelectedItem();
		Integer result = null;
		if ("+".equals(op)) {
			result = new Integer(v1 + v2);
		}
		if ("*".equals(op)) {
			result = new Integer(v1 * v2);
		}
		if ("-".equals(op)) {
			result = new Integer(v1 - v2);
		}
		if ("/".equals(op)) {
			result = new Integer(v1 / v2);
		}
		answer.setText(result.toString());
	}
}